package com.shaoshaohuo.app.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.liam.imageload.LoadUtils;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.adapter.CarTypeSecondListAdapter;
import com.shaoshaohuo.app.adapter.OftenAddressListAdapter1;
import com.shaoshaohuo.app.adapter.RunlineAdapter1;
import com.shaoshaohuo.app.constant.CarOption;
import com.shaoshaohuo.app.constant.FileType;
import com.shaoshaohuo.app.db.DaoUtils;
import com.shaoshaohuo.app.entity.Addressinfo;
import com.shaoshaohuo.app.entity.BaseEntity;
import com.shaoshaohuo.app.entity.CarTypeFirst;
import com.shaoshaohuo.app.entity.CarTypeSecond;
import com.shaoshaohuo.app.entity.Carinfo;
import com.shaoshaohuo.app.entity.Lineinfo;
import com.shaoshaohuo.app.entity.UploadImageEntity;
import com.shaoshaohuo.app.entity.UserInfoEntity;
import com.shaoshaohuo.app.entity.post.CarInfo;
import com.shaoshaohuo.app.net.HttpRequest;
import com.shaoshaohuo.app.net.RequestService;
import com.shaoshaohuo.app.utils.CameraUtil;
import com.shaoshaohuo.app.utils.ImageLoadUtil;
import com.shaoshaohuo.app.utils.NumberUtil;
import com.shaoshaohuo.app.view.CarVolumePopwindow;
import com.shaoshaohuo.app.view.TopbarView;

import org.hybridsquad.android.library.CropHandler;
import org.hybridsquad.android.library.CropHelper;
import org.hybridsquad.android.library.CropParams;

import java.util.List;

/**
 * 车辆认证
 * Created by cao on 2016/3/21.
 */
public class AuthCarActivity extends BaseActivity implements View.OnClickListener, CropHandler {


    public static final int SELECT_IMAGE_ID_FRONT = 0;
    public static final int SELECT_IMAGE_ID_BEHIND = SELECT_IMAGE_ID_FRONT + 1;
    public static final int SELECT_IMAGE_XINGSHIZHENG = SELECT_IMAGE_ID_BEHIND + 1;
    public static final int SELECT_IMAGE_CAR_ZHENGMIAN = SELECT_IMAGE_XINGSHIZHENG + 1;
    public static final int SELECT_IMAGE_CAR_CEMIAN = SELECT_IMAGE_CAR_ZHENGMIAN + 1;
    public static final int SELECT_IMAGE_CAR_45 = SELECT_IMAGE_CAR_CEMIAN + 1;

    public static final int REQUESTCODE_LINE = 1;
    public static final int REQUESTCODE_ADDRESS = 2;

    private int currentSelectImageType = SELECT_IMAGE_ID_FRONT;


    private TopbarView mTopbarView;

    private View mTypeLayout;
    private View mCarNumberLayout;
    private View mTijiLayout;
    private View mXingshizhengLayout;
    private View mCarImage1Layout;
    private View mCarImage2Layout;
    private View mCarImage3Layout;
    private TextView mTypeText;
    private EditText mCarNumberText;
    private EditText mTijiText;
    private ImageView mXingshizhengImage;
    private ImageView mCar1Image;
    private ImageView mCar2Image;
    private ImageView mCar3Image;
    private Button mSendToolButton;
    private TextView mXingshizhengTipsText;
    private Button mSubmitCarButton;
    private View mZaizhongLayout;
    private EditText mZaizhongText;
    private View mFlagAuth;
    private ImageView ivAuthFlag;
    private View mOftenAddressLayout;
    private ListView mAddressListview;
    private ListView mLineListview;
    private View mRunLineLayout;


    private String cartype = "";
    private String id = "";
    private String carcid = "";
    private String carphoto1 = "";
    private String carphoto2 = "";
    private String carphoto3 = "";
    private String carnum = "";
    private String caryear = "";
    private String cardriverimg = "";
    private String carlong = "";
    private String carwidth = "0";
    private String carheight = "0";
    private String carweight = "";

    private String mDriverImgUri = "";
    private String mCarimage1Uri = "";
    private String mCarimage2Uri = "";
    private String mCarimage3Uri = "";

    private OftenAddressListAdapter1<Addressinfo> mAddressAdapter;
    private RunlineAdapter1<Lineinfo> mLinedapter;

    private CarTypeFirst mSelectTool;
    private CarTypeSecond mSelectCarType;

    private CarVolumePopwindow volumePop;

    private AlertDialog carWeightDialog;

    CropParams mCropParams = new CropParams();


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auth_car);
        initView();
        setupView();
        requestData();
    }

    private void initView() {

        mTopbarView = (TopbarView) this.findViewById(R.id.topbar);

        mTypeLayout = findViewById(R.id.layout_type);
        mCarNumberLayout = findViewById(R.id.layout_car_number);
        mTijiLayout = findViewById(R.id.layout_tiji);
        mXingshizhengLayout = findViewById(R.id.layout_xingshizheng);
        mCarImage1Layout = findViewById(R.id.layout_carImage_zhengmian);
        mCarImage2Layout = findViewById(R.id.layout_carImage_cemian);
        mCarImage3Layout = findViewById(R.id.layout_carImage_45du);

        mRunLineLayout = findViewById(R.id.layout_run_line);
        mOftenAddressLayout = findViewById(R.id.layout_often_address);
        mAddressListview = (ListView) findViewById(R.id.listview_often_address);
        mLineListview = (ListView) findViewById(R.id.listview_line);

        mTypeText = (TextView) findViewById(R.id.textview_type);
        mCarNumberText = (EditText) findViewById(R.id.edittext_car_number);
        mTijiText = (EditText) findViewById(R.id.textview_tiji);

        mXingshizhengImage = (ImageView) findViewById(R.id.imageview_xingshizheng);
        mCar1Image = (ImageView) findViewById(R.id.imageview_id_image_zhengmian);
        mCar2Image = (ImageView) findViewById(R.id.imageview_id_image_fanmian);
        mCar3Image = (ImageView) findViewById(R.id.imageview_id_image_45);
        mSendToolButton = (Button) findViewById(R.id.button_ok);
        mXingshizhengTipsText = (TextView) findViewById(R.id.textview_xingshizheng_tips);
        mZaizhongLayout = findViewById(R.id.layout_zaizhong);
        mZaizhongText = (EditText) findViewById(R.id.textview_zaizhong);
        mSubmitCarButton = (Button) findViewById(R.id.button_ok);
        mFlagAuth = findViewById(R.id.layout_auth_flag);
        ivAuthFlag = (ImageView) findViewById(R.id.iv_auth_flag);
    }


    private void setupView() {
        mTopbarView.setCenterText("车辆认证");
        mTopbarView.setLeftView(true, true);

        setJidongche(true);

        mTypeLayout.setOnClickListener(this);

        mXingshizhengLayout.setOnClickListener(this);
        mCarImage1Layout.setOnClickListener(this);
        mCarImage2Layout.setOnClickListener(this);
        mCarImage3Layout.setOnClickListener(this);
        mSubmitCarButton.setOnClickListener(this);

        mOftenAddressLayout.setOnClickListener(this);
        mRunLineLayout.setOnClickListener(this);


    }


    private void setJidongche(boolean isTrue) {
        if (isTrue) {
            mCarNumberLayout.setVisibility(View.VISIBLE);
            mTijiLayout.setVisibility(View.VISIBLE);
            mXingshizhengLayout.setVisibility(View.VISIBLE);
            mXingshizhengTipsText.setVisibility(View.VISIBLE);
            mZaizhongLayout.setVisibility(View.VISIBLE);
        } else {
            mCarNumberLayout.setVisibility(View.GONE);
            mTijiLayout.setVisibility(View.GONE);
            mXingshizhengLayout.setVisibility(View.GONE);
            mXingshizhengTipsText.setVisibility(View.GONE);
            mZaizhongLayout.setVisibility(View.GONE);
        }
    }

    private void requestData() {
        startLoadingDialog();
        RequestService.getInstance().getUserInfo(this, UserInfoEntity.class, new HttpRequest.RequestListener() {

            @Override
            public void onSuccess(int requestCode, BaseEntity resultData) {
                dismissLoadingDialog();
                if (resultData.isOk()) {
                    UserInfoEntity entity = (UserInfoEntity) resultData;
                    updateUi(entity.getData());
                } else {
                    showToast(resultData.getMsg());
                }
            }

            @Override
            public void onFailed(int requestCode, Exception error, String msg) {
                dismissLoadingDialog();
                showToast(R.string.please_check_network);
            }
        });
    }

    private void updateUi(UserInfoEntity.UserInfo data) {
        Carinfo carinfo = data.getCarinfo();
        if (data == null) {
            return;
        }
        List<CarTypeFirst> findAllCartype = DaoUtils.findAllCartype();
        for (int i = 0; i < findAllCartype.size(); i++) {
            if (findAllCartype.get(i).getTypeid().equals(carinfo.getCartype())) {
                if (i == 0) {
                    setJidongche(true);
                } else {
                    setJidongche(false);
                }
            }
        }
        mTypeText.setText(carinfo.getCarcname());
        mCarNumberText.setText(carinfo.getCarnum());

        setLineAdapter(data.getLineinfo());

        setAddressAdapter(data.getAddressinfo());

        try {
            mTijiText.setText((Double.parseDouble(carinfo.getCarlong()) / 1000) + "");
            mZaizhongText.setText((Double.parseDouble(carinfo.getCarweight()) / 1000) + "");
        } catch (Exception e) {
            e.printStackTrace();
        }

        ImageLoader.getInstance().displayImage(carinfo.getCarphoto1(), mCar1Image,
                ImageLoadUtil.getDisplayImageOptions(0, 10));
        ImageLoader.getInstance().displayImage(carinfo.getCarphoto2(), mCar2Image,
                ImageLoadUtil.getDisplayImageOptions(0, 10));
        ImageLoader.getInstance().displayImage(carinfo.getCarphoto3(), mCar3Image,
                ImageLoadUtil.getDisplayImageOptions(0, 10));
        ImageLoader.getInstance().displayImage(carinfo.getCardriverimg(), mXingshizhengImage,
                ImageLoadUtil.getDisplayImageOptions(0, 10));

        setCarAuthEnable(data);

        cartype = carinfo.getCartype();
        carcid = carinfo.getCarcid();
        id = carinfo.getId();
        carphoto1 = carinfo.getCarphoto1();
        carphoto2 = carinfo.getCarphoto2();
        carphoto3 = carinfo.getCarphoto3();
        carnum = carinfo.getCarnum();
        caryear = carinfo.getCaryear();
        cardriverimg = carinfo.getCardriverimg();
        carlong = carinfo.getCarlong();
        carwidth = carinfo.getCarwidth();
        carheight = carinfo.getCarheight();
        carweight = carinfo.getCarweight();

    }

    private void setLineAdapter(List<Lineinfo> list) {
        if (mLinedapter == null) {
            mLinedapter = new RunlineAdapter1<>(this, list, false);
            mLineListview.setAdapter(mLinedapter);
        } else {
            mLinedapter.setData(list);
        }
    }

    private void setAddressAdapter(List<Addressinfo> list) {
        if (mAddressAdapter == null) {
            mAddressAdapter = new OftenAddressListAdapter1<>(this, list, false);
            mAddressListview.setAdapter(mAddressAdapter);
        } else {
            mAddressAdapter.setData(list);
        }
    }

    private void setCarAuthEnable(UserInfoEntity.UserInfo data) {
        String authStatus = data.getCarinfo().getVerifystatus();
        if ("3".equals(authStatus) || "4".equals(authStatus)) {
            mTypeLayout.setEnabled(false);
            mXingshizhengLayout.setEnabled(false);
            mCarImage1Layout.setEnabled(false);
            mCarNumberText.setEnabled(false);
            mTijiText.setEnabled(false);
            mZaizhongText.setEnabled(false);
            mFlagAuth.setVisibility(View.VISIBLE);
            if ("3".equals(authStatus)) {
                ivAuthFlag.setImageResource(R.drawable.icon_auth_yes);
            } else {
                ivAuthFlag.setImageResource(R.drawable.icon_un_auth);
            }
        } else {
            mFlagAuth.setVisibility(View.GONE);
        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.layout_often_address:
                Intent intent = new Intent(this, OftenAddressActitity.class);
                startActivityForResult(intent, REQUESTCODE_ADDRESS);
                break;
            case R.id.layout_run_line:
                Intent intent1 = new Intent(this, RunLineActivity.class);
                startActivityForResult(intent1, REQUESTCODE_LINE);
                break;
            case R.id.layout_id_zhengmian:
                selectImage(SELECT_IMAGE_ID_FRONT);
                break;
            case R.id.layout_id_fanmian:
                selectImage(SELECT_IMAGE_ID_BEHIND);
                break;
            case R.id.layout_type:
                showTypeDialog();
                break;
            case R.id.layout_tiji:
                selectVocume();
                break;
            case R.id.layout_zaizhong:
                selectCarWeight();
                break;
            case R.id.layout_xingshizheng:
                selectImage(SELECT_IMAGE_XINGSHIZHENG);
                break;
            case R.id.layout_carImage_zhengmian:
                selectImage(SELECT_IMAGE_CAR_ZHENGMIAN);
                break;
            case R.id.layout_carImage_cemian:
                selectImage(SELECT_IMAGE_CAR_CEMIAN);
                break;
            case R.id.layout_carImage_45du:
                selectImage(SELECT_IMAGE_CAR_45);
                break;
            case R.id.button_ok:
                uploadCarImage();
                break;
        }
    }

    //选择照片
    private void selectImage(int selectType) {

        currentSelectImageType = selectType;

        AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
        builder1.setItems(new String[]{"相机", "相册"}, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                    case 0:
                        CameraUtil.capture(AuthCarActivity.this);
                        break;
                    case 1:
                        CameraUtil.photo(AuthCarActivity.this);
                        break;
                }
            }
        });
        builder1.create().show();
    }

    private void showTypeDialog() {
        final List<CarTypeFirst> allProvince = DaoUtils.findAllCartype();
        mSelectTool = allProvince.get(0);
        cartype = mSelectTool.getTypeid();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final List<CarTypeSecond> findAllProvince = DaoUtils.findAllCartype(mSelectTool.getTypeid());
        CarTypeSecondListAdapter<CarTypeSecond> adapter = new CarTypeSecondListAdapter<CarTypeSecond>(this,
                findAllProvince, false);
        builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                mSelectCarType = findAllProvince.get(which);
                mTypeText.setText(mSelectCarType.getName());
                carcid = mSelectCarType.getCid();
            }
        });
        builder.create().show();
    }

    private void selectVocume() {

        if (volumePop != null && volumePop.isShowing()) {
            return;
        }

        volumePop = new CarVolumePopwindow(this);
        volumePop.setOnSelectListener(new CarVolumePopwindow.OnSelectListener() {

            @Override
            public void onSelect(int ont, int two, int three, String str) {
                mTijiText.setText(str);
            }
        });
        volumePop.showLocation(mTijiLayout);
    }

    protected void selectCarWeight() {
        if (carWeightDialog != null && carWeightDialog.isShowing()) {
            return;
        }
        if (carWeightDialog == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setItems(CarOption.carWeightItems, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
//                     carweight = which + 1;
//                     setCarRequireText();
                }
            });
            carWeightDialog = builder.create();
            carWeightDialog.setTitle("载重");
        }
        carWeightDialog.show();
    }


    private void uploadCarImage() {

        if (TextUtils.isEmpty(cartype)) {
            showToast("请选择配送工具");
            return;
        }
        if (TextUtils.isEmpty(carcid)) {
            showToast("请输入车辆类型");
            return;
        }

        List<CarTypeFirst> findAllCartype = DaoUtils.findAllCartype();

        carlong = mTijiText.getText().toString().trim();
        carweight = mZaizhongText.getText().toString().trim();
        carnum = mCarNumberText.getText().toString().trim();

        if (cartype.equals(findAllCartype.get(0).getTypeid())) {
            if (TextUtils.isEmpty(carlong)) {
                showToast("请填写车身长度");
                return;
            }
            if (TextUtils.isEmpty(carweight)) {
                showToast("请填写车身载重");
                return;
            }
            if (TextUtils.isEmpty(carnum)) {
                showToast("请填写车牌号");
                return;
            }
            if (TextUtils.isEmpty(cardriverimg) && TextUtils.isEmpty(mDriverImgUri)) {
                showToast("请设置驾驶证照片");
                return;
            }
        }

        if (TextUtils.isEmpty(carphoto1) && TextUtils.isEmpty(mCarimage1Uri)) {
            showToast("请完善车身照片");
            return;
        }
        if (TextUtils.isEmpty(carphoto2) && TextUtils.isEmpty(mCarimage2Uri)) {
            showToast("请完善车身照片");
            return;
        }
        if (TextUtils.isEmpty(carphoto3) && TextUtils.isEmpty(mCarimage3Uri)) {
            showToast("请完善车身照片");
            return;
        }

        CarInfo carInfo = new CarInfo();
        carInfo.setId(id);
        carInfo.setCartype(cartype);
        carInfo.setCarcid(carcid);
        carInfo.setCarphoto1(carphoto1);
        carInfo.setCarphoto2(carphoto2);
        carInfo.setCarphoto3(carphoto3);
        carInfo.setCarnum(carnum);
        carInfo.setCaryear(caryear);
        carInfo.setCardriverimg(cardriverimg);
        carInfo.setCarlong((NumberUtil.parse(carlong) * 1000) + "");
        carInfo.setCarwidth(TextUtils.isEmpty(carwidth) ? "1" : carwidth);
        carInfo.setCarheight(TextUtils.isEmpty(carheight) ? "1" : carheight);
        carInfo.setCarweight((NumberUtil.parse(carweight) * 1000) + "");

        if (TextUtils.isEmpty(mDriverImgUri) && TextUtils.isEmpty(mCarimage1Uri) && TextUtils.isEmpty(mCarimage2Uri)
                && TextUtils.isEmpty(mCarimage3Uri)) {
            uploadCarInfo(carInfo);
        } else {
            uploadFile(carInfo, mDriverImgUri, FileType.IMAGE, SELECT_IMAGE_XINGSHIZHENG);
        }

    }

    private void uploadCarInfo(CarInfo carInfo) {
        startLoadingDialog();
        if (carInfo.getId() != null && !"".equals(carInfo.getId()) && carInfo.getCarcid() != null
                && !"".equals(carInfo.getCarcid())) {
            RequestService.getInstance().updateCar(this, carInfo, BaseEntity.class, new HttpRequest.RequestListener() {

                @Override
                public void onSuccess(int requestCode, BaseEntity resultData) {
                    dismissLoadingDialog();
                    if (resultData.isOk()) {
                        showToast("车辆信息更新成功");
//                        getUserInfo();
                    } else {
                        showToast(resultData.getMsg());
                    }
                }

                @Override
                public void onFailed(int requestCode, Exception error, String msg) {
                    dismissLoadingDialog();
                    showToast(R.string.please_check_network);
                }
            });
        } else {
            RequestService.getInstance().saveCar(this, carInfo, BaseEntity.class, new HttpRequest.RequestListener() {

                @Override
                public void onSuccess(int requestCode, BaseEntity resultData) {
                    dismissLoadingDialog();
                    if (resultData.isOk()) {
                        showToast("车辆信息保存成功");
                    } else {
                        showToast(resultData.getMsg());
                    }
                }

                @Override
                public void onFailed(int requestCode, Exception error, String msg) {
                    dismissLoadingDialog();
                    showToast(R.string.please_check_network);
                }
            });
        }
    }


    private void uploadFile(final CarInfo releaseInfo, String uri, final String type, final int uploadId) {

        if (TextUtils.isEmpty(uri)) {
            setUrl(uploadId, null, releaseInfo);
            return;
        }

        startLoadingDialog();
        RequestService.getInstance().uploadImage(this, uri, type, UploadImageEntity.class, new HttpRequest.RequestListener() {

            @Override
            public void onSuccess(int requestCode, BaseEntity resultData) {
                dismissLoadingDialog();
                if (resultData.isOk()) {
                    UploadImageEntity entity = (UploadImageEntity) resultData;
                    setUrl(uploadId, entity, releaseInfo);
                } else {
                    showToast(resultData.getMsg());
                }
            }

            @Override
            public void onFailed(int requestCode, Exception error, String msg) {
                dismissLoadingDialog();
                showToast(msg);
            }
        });
    }


    protected void setUrl(int uploadId, UploadImageEntity entity, CarInfo releaseInfo) {
        switch (uploadId) {
            case SELECT_IMAGE_XINGSHIZHENG:
                if (entity != null) {
                    releaseInfo.setCardriverimg(entity.getData().getFile());
                    ;
                }
                uploadFile(releaseInfo, mCarimage1Uri, FileType.IMAGE, SELECT_IMAGE_CAR_ZHENGMIAN);
                break;
            case SELECT_IMAGE_CAR_ZHENGMIAN:
                if (entity != null) {
                    releaseInfo.setCarphoto1(entity.getData().getFile());
                    ;
                }
                uploadFile(releaseInfo, mCarimage2Uri, FileType.IMAGE, SELECT_IMAGE_CAR_CEMIAN);
                break;
            case SELECT_IMAGE_CAR_CEMIAN:
                if (entity != null) {
                    releaseInfo.setCarphoto2(entity.getData().getFile());
                    ;
                }
                uploadFile(releaseInfo, mCarimage3Uri, FileType.IMAGE, SELECT_IMAGE_CAR_45);
                break;
            case SELECT_IMAGE_CAR_45:
                if (entity != null) {
                    releaseInfo.setCarphoto3(entity.getData().getFile());
                    ;
                }
                uploadCarInfo(releaseInfo);
                break;
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        CameraUtil.handleResult(this, requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case REQUESTCODE_ADDRESS:
                    requestData(REQUESTCODE_ADDRESS);
                    break;
                case REQUESTCODE_LINE:
                    requestData(REQUESTCODE_LINE);
                    break;
            }

        }
    }

    private void requestData(final int code) {
        RequestService.getInstance().getUserInfo(this, UserInfoEntity.class, new HttpRequest.RequestListener() {

            @Override
            public void onSuccess(int requestCode, BaseEntity resultData) {
                dismissLoadingDialog();
                if (resultData.isOk()) {
                    UserInfoEntity entity = (UserInfoEntity) resultData;
                    if (code == REQUESTCODE_ADDRESS) {
                        setAddressAdapter(entity.getData().getAddressinfo());
                    } else if (code == REQUESTCODE_LINE) {
                        setLineAdapter(entity.getData().getLineinfo());
                    }
                } else {
                    showToast(resultData.getMsg());
                }
            }

            @Override
            public void onFailed(int requestCode, Exception error, String msg) {
                dismissLoadingDialog();
                showToast(R.string.please_check_network);
            }
        });
    }

    @Override
    public CropParams getCropParams() {
        return mCropParams;
    }

    @Override
    public void onPhotoCropped(Uri u) {
        String uri = u.getPath();
        switch (currentSelectImageType) {
            case SELECT_IMAGE_XINGSHIZHENG:
                LoadUtils.getInstance().loadImage(mXingshizhengImage, "file://" + uri, 0, 2);
                mDriverImgUri = uri;
                break;
            case SELECT_IMAGE_CAR_ZHENGMIAN:
                LoadUtils.getInstance().loadImage(mCar1Image, "file://" + uri, 0, 5);
                mCarimage1Uri = uri;
                break;
            case SELECT_IMAGE_CAR_CEMIAN:
                LoadUtils.getInstance().loadImage(mCar2Image, "file://" + uri, 0, 5);
                mCarimage2Uri = uri;
                break;
            case SELECT_IMAGE_CAR_45:
                LoadUtils.getInstance().loadImage(mCar3Image, "file://" + uri, 0, 5);
                mCarimage3Uri = uri;
                break;
        }

    }


    @Override
    public void onCropCancel() {
    }

    @Override
    public void onCropFailed(String message) {
    }

    @Override
    public Activity getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        if (getCropParams() != null)
            CropHelper.clearCachedCropFile(getCropParams().uri);
        super.onDestroy();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

}
